import unittest,threading
import time
from threadpool import ThreadPool,makeRequests

def test_task(name):
    print(f"{threading.current_thread().name}: ",name)
    time.sleep(10)

class TestTask(unittest.TestCase):
    def test01(self):
        test_task(1)
    def test02(self):
        test_task(2)
    def test03(self):
        test_task(3)
    def test04(self):
        test_task(4)
    def test05(self):
        test_task(5)
    def test06(self):
        test_task(6)
    def test07(self):
        test_task(7)
    def test08(self):
        test_task(8)
    def test09(self):
        test_task(9)
    def test10(self):
        test_task(10)


def suite():
    #创建⼀个测试套件
    suite = unittest.TestSuite()
    #创建⼀个⽤例加载对象
    loader = unittest.TestLoader()
    #获取用例数量
    suite.addTest(loader.loadTestsFromTestCase(TestTask))
    for test in suite:
        # print(test._tests)
        return (test._tests)

def action(case_list):
    t1 = unittest.runner.TextTestRunner()
    t1.run(case_list)

if __name__ == '__main__':
    print('开始')
    pool = ThreadPool(10)  # 启动10个线程运行
    test_case = suite()  # 获取测试用例
    requests = makeRequests(action, test_case, callback=None)  # 初始化要执行的任务
    [pool.putRequest(req) for req in requests]
    pool.wait()  # 等待任务完成
    print('结束')



